<?php
namespace app\app\controller;

use think\Controller;
class Course extends Controller
{
    public function index()
    {
        $talk = new Talk();
        $if_login = $talk->check_login();
        if ($if_login == false){
            $this->assign('login_status','never');
        }else {
            $talk = new Talk();
            $never_read_num = $talk->never_read();
            $this->assign('never_read_num',$never_read_num);
            $this->assign('never_read_num',$never_read_num);
            $this->assign('user_name',session('user_name','','app'));
            $this->assign('user_id',session('user_id','','app'));
            $this->assign('login_status','have');
            $this->assign('logout_url',url('index.php/app/talk/logout'));
            $this->assign('personal_url',url('index.php/app/main/personal_set'));
        }
        $model = model('Course');
        $coursemodule = $model->getCourse();
        $this->assign('coursemodule',$coursemodule);
        $this->assign('title','教程');
        $this->assign('active','course');
        return $this->fetch('index');
    }
    
    public function get_course_content()
    {
        $result = array('err'=>'1','content' => '');
        $course_id = input('post.course_id');
        $content = db('course')->field('content')->where('id',$course_id)->value('content');
        if ($content == false || $content == ''){
            $result['content'] = '教程内容为空或获取教程失败！';
            return $result;
        }
        $result['err'] = '0';
        $result['content'] = $content;
        return $result;
    }
    
    public function search_course()
    {
        $result = array('err' => '1','content' => '');
        $keyword = input('post.keyword');
        $course = db('course')->field(['id','course'])->where('course','like','%'.$keyword.'%')->select();
        if ($course == false){
            $result['content'] = '查询失败或所查内容为空';
            return $result;
        }
        $result['data'] = $course;
        $result['err'] = '0';
        $result['content'] = '查询成功！';
        return $result;
    }
    
    
}